<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<title>用户管理</title>

<link rel="stylesheet" href="__PUBLIC__/js/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<link rel="stylesheet" href="__PUBLIC__/js/ztree/css/demo.css" type="text/css">

<link rel="stylesheet" href="__PUBLIC__/css/inner.css" type="text/css">

<script type="text/javascript" src="__PUBLIC__/js/jquery.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ztree/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ztree/js/jquery.ztree.excheck-3.5.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery.table.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery.form.js"></script>
<script type="text/javascript">
	$(function() {
		
	});
	function queryPage(id){
		 $("#curPage").val(id);
		 $('#usermanageFromId').submit();
	}
	var zTree;
	var treeNodes;
	var setting = {
			//数据是否采用简单 Array 格式，默认false
			data: {
					simpleData: {
						enable: true
					}
				},
			//在isSimpleData格式下，当前节点id属性
			check: {
				enable: true
			},
			treeNodeKey: "id",
			treeNodeParentKey: "pid",
		};

	function showRoleTree(id){
		$("#userid").val(id);
		$("#rolrTreeDiv").show();
		$.ajax({
			async : false,
			cache : false,
			type : 'POST',
			dataType : "json",
			data:{'uid':id},
			//请求的action路径
			url : "<?php echo U('Rbac/getRoleJson/');?>/t/"+(new Date()),
			//请求失败处理函数   
			error : function() {
				alert('请求失败');
			},
			//请求成功后处理函数。
			success : function(result) {
				//把后台封装好的简单Json格式赋给treeNodes 
				treeNodes =  result;
				$.fn.zTree.init($("#tree"), setting, treeNodes);
			}
		});
	}
	function saveUser(){
		var c1 = "";
		var userid=$("#userid").val();
		var zTree = $.fn.zTree.getZTreeObj("tree");
		$.each(zTree.getCheckedNodes(), function() {
			c1 += this.id + ","
		});
		if(''!=c1){
			$.ajax({
				async : false,
				cache : false,
				type : 'POST',
				dataType : "json",
				data:{'userid':userid,'rids':c1},
				//请求的action路径
				url : "<?php echo U('Rbac/saveUserRole/');?>/t/"+(new Date()),
				//请求失败处理函数   
				error : function() {
					alert('请求失败');
				},
				//请求成功后处理函数。
				success : function(result) {
					alert('ok');
				}
			});
		}
	}
	</script>
<style>
.textClass{
	border-radius: 4px;
	  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
	   font-size: 14px;
	    line-height: 1.42857;
    padding: 6px 12px;
}
.panel-heading{
	margin-bottom: 0px;
}
.main_table{
	border-left: 1px solid #E3E3E3;
	border-right: 2px solid #E3E3E3;
	border-top: 2px solid #E3E3E3;
}
</style>
</head>
<body>
		<div>
			<div class='panel-heading'>
			<form id="usermanageFromId" style="margin-bottom: 0px;">
			<input type="hidden" name="p" id="curPage"> 
			<label>登录名称</label>
			<span class='k-textbox'> 
			  <input type="text" name="username" class="textClass">
			</span>
			<a class="btn blue-bg" id="usermanageSearchId">快速查询</a>
			</form>
			</div>
			<div style="display: inline;">
				<div id="usermanageTable" style="width: 40%;position: ralative;float:left; padding-left: 10px;">
				<table  class='main_table'  style="border: 1px #ccc solid; width: 100%;">
				    <thead >
				    <tr>
				       <th class='state1'>编号</th><th class='state1'>用户名</th><th class='state1'>操作</th>
				    </tr>
				    </thead>
				     <tbody class='records'>
						<?php if(is_array($list)): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$list): $mod = ($i % 2 );++$i;?><tr  style="border: 1px #ccc solid;">
						       <td><?php echo ($list["id"]); ?></td><td><?php echo ($list["username"]); ?></td>
						       <td><a class="btn blue-bg" onclick="showRoleTree(<?php echo ($list["id"]); ?>)">分配角色</a></td>
						    </tr><?php endforeach; endif; else: echo "" ;endif; ?>
					 </tbody>
					</table>
				    <?php echo ($page); ?>
				</div>
				
				<div id="rolrTreeDiv" style="position:relative;float:left;height: 400px;padding:0;margin-left: 100px;display: none;">
				<ul id="tree"  class="ztree" style="position:relative;float:left;padding:0;margin: 0;"></ul>
				<div  style="position:relative;float:right;padding:0;margin-left: 10px;">
				   <form id="editUser" style="margin-bottom: 0px;">
				    <div>
				    <label>用户名</label>
					<span class='k-textbox'> 
					<input type="hidden" id="userid" name="userid">
					  <input type="text" name="username" class="textClass">
					</span>
				    </div>
				    <div>
				    <label>密&nbsp;&nbsp;&nbsp;&nbsp;码</label>
					<span class='k-textbox'> 
					  <input type="text" name="username" class="textClass">
					</span>
				    </div>
				    <div>
				     <a class="btn blue-bg"  onclick="saveUser()" id="usermanageSearchId">保存</a>
				    </div>
				    </form>
				</div>
				</div>
				
		</div>
	</div>
</body>
</html>